package juc.thread.reentrantLock;

import java.util.concurrent.locks.ReentrantLock;

/*
* ReentrantLock-测试可打断
* */
public class Test2 {
    private static ReentrantLock lock=new ReentrantLock();
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
//                lock.lockInterruptibly();让等待锁线程可以被打断
                lock.lock();
                System.out.println(Thread.currentThread().getName()+"获得锁...");
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
        }, "t1");
        lock.lock();
        System.out.println("main 获得锁...");
        t1.start();
        //一段时间后t1没抢到锁 就打断该线程 让其退出等待锁过程
        Thread.sleep(3000);
        t1.interrupt();
    }
}
